/*******************************************************************************
 * Copyright (c) 2011 TXT e-solutions SpA
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * This work was performed within the IoT_at_Work Project
 * and partially funded by the European Commission's
 * 7th Framework Programme under the research area ICT-2009.1.3
 * Internet of Things and enterprise environments.
 *
 *
 * Authors:
 *     Cristoforo Seccia (TXT e-solutions SpA)
 *
 * Contributors:
 *      Domenico Rotondi (TXT e-solutions SpA)
 *******************************************************************************/
package it.txt.access.capability.demo.soap.client;

import it.txt.access.capability.commons.view.wait.WaitFrameController;
import it.txt.access.capability.factory.CapabilitySchemaFactoryException;
import it.txt.access.capability.factory.CapabilitySchemaFactory;
import it.txt.access.capability.demo.soap.client.view.ClientGUIController;
import it.txt.access.capability.demo.schema.factory.CapabilityDemoSchemaFactoryException;
import it.txt.access.capability.demo.schema.factory.CapabilityDemoSchemaFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;


/**
 * -----------------------------------------------------------------------------
 * Graphical Application that allows users to connect to the server side by prov
 * iding a capability request in order to demostrate the facilities of the capab
 * ility authorization approach.
 *
 *
 * ******************************************
 *
 * @version 1.0
 * @author  http://www.txtgroup.com
 * @author  Cristoforo Seccia (cristoforo.seccia@txtgroup.com)
 * @contributor Domenico Rotondi (domenico.rotongi@txtgroup.com)
 *
 * -----------------------------------------------------------------------------
 */
public class ClientMainListener {

    private static final Logger LOGGER = Logger.getLogger(ClientMainListener.class.getName());

    public static void main(String[] args) {
        WaitFrameController wfc = null;
        try {
            wfc = new WaitFrameController("Access Capability Demo Client");
            wfc.displayApplicationLoadingFrame();
            initializeLookAndFeels();
            CapabilitySchemaFactory.initCapabilityCreator("../Capability_Schemas/");
            CapabilityDemoSchemaFactory.initCapabilityCreator();
            if (wfc.isApplicationLoadingFrameVisible()) {
                wfc.closeApplicationLoadingFrame();
            }
            ClientGUIController cguic = new ClientGUIController();
            cguic.createAndShowClient();
        }
        catch (CapabilitySchemaFactoryException ex) {
            if (wfc.isApplicationLoadingFrameVisible()) {
                wfc.closeApplicationLoadingFrame();
            }
            LOGGER.log(Level.SEVERE, null, ex);
        }
        catch (CapabilityDemoSchemaFactoryException ex) {
            if (wfc.isApplicationLoadingFrameVisible()) {
                wfc.closeApplicationLoadingFrame();
            }
            LOGGER.log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Installs the JGoodies Look & Feels, if available, in classpath.
     */
    public static void initializeLookAndFeels() {
        try {
            LOGGER.log(Level.INFO, "Error while setting L&F. Set the system default L&F.");
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }
    }
}
